<?php

namespace Lib\Behavior;

use Think\Behavior,
    Common\Common\AppVerify;

class RouterBehavior extends Behavior {

    // 行为参数定义
    protected $options   =  array(
    );

    // 行为扩展的执行入口
    public function run(&$params)
    {
        if (AppVerify::check())
        {
            $apiAction = $_REQUEST['api_action'];
            $actionArr = explode('.', $apiAction);
            //$moduleName = ucfirst(array_shift($actionArr));
            $moduleName = 'Home';
            $actionName = ucfirst(array_pop($actionArr));
            $controllerName = implode('', array_map('ucfirst', $actionArr));
            $_SERVER['PATH_INFO'] = $moduleName.'/'.$controllerName.'/'.$actionName.'Action';
        }
        else
        {
            // 验证错误出口，可替换
            $_SERVER['PATH_INFO'] = 'Lib/Error/defaultAction';
        }
    }

}
